// $ANTLR 3.0.1 BPSL.g 2008-05-10 14:09:11

	package patternmining.model.construction;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;


import org.antlr.runtime.tree.*;

/** Gramar for the language SBPSL.
SBPSL is an acronym for "structured" Balanced Pattern Specification Language.
The language is a reduced First Order Logic and as a part of BPSL meant to specify structural aspects of software design patterns.

A specification file has the form:
------------------------------
\<patternname> :=

\exist
var1, var2 \element \C;
var3, var4 \element \M;
var5, var6 \element \C;
var7, var8 \element \V;
predicate1(var2, var7) ^ predicate2(var5, var3) ^ ... ^ predicateN(varX, varY)
-----------------------------
Constraints:
The predicate section follows the variable declaration section.
There is no necessary order in the domains throughout the variable definition section.
There must be at least one variable of some type defined.
The variables of one type might be defined in several statements.  	
 
*/
class BPSLParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "DISJUNCTION", "ROOT", "VARDEF", "FORMULA", "CLASSDEF", "TYPEDVARDEF", "METHODDEF", "PATTERNNAME", "ID", "PREDICATE", "WS", "':='", "'\\\\exist'", "','", "'\\\\element'", "';'", "'\\\\C'", "'\\\\V'", "'\\\\M'", "'('", "')'"
    };
    public static final int TYPEDVARDEF=9;
    public static final int DISJUNCTION=4;
    public static final int WS=14;
    public static final int METHODDEF=10;
    public static final int FORMULA=7;
    public static final int PATTERNNAME=11;
    public static final int CLASSDEF=8;
    public static final int ID=12;
    public static final int VARDEF=6;
    public static final int EOF=-1;
    public static final int ROOT=5;
    public static final int PREDICATE=13;

        public BPSLParser(TokenStream input) {
            super(input);
        }
        
    protected TreeAdaptor adaptor = new CommonTreeAdaptor();

    public void setTreeAdaptor(TreeAdaptor adaptor) {
        this.adaptor = adaptor;
    }
    public TreeAdaptor getTreeAdaptor() {
        return adaptor;
    }

    public String[] getTokenNames() { return tokenNames; }
    public String getGrammarFileName() { return "BPSL.g"; }


    public static class specification_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start specification
    // BPSL.g:52:1: specification : PATTERNNAME ':=' formula ;
    public final specification_return specification() throws RecognitionException {
        specification_return retval = new specification_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        Token PATTERNNAME1=null;
        Token string_literal2=null;
        formula_return formula3 = null;


        CommonTree PATTERNNAME1_tree=null;
        CommonTree string_literal2_tree=null;

        try {
            // BPSL.g:52:15: ( PATTERNNAME ':=' formula )
            // BPSL.g:52:17: PATTERNNAME ':=' formula
            {
            root_0 = (CommonTree)adaptor.nil();

            PATTERNNAME1=(Token)input.LT(1);
            match(input,PATTERNNAME,FOLLOW_PATTERNNAME_in_specification88); 
            PATTERNNAME1_tree = (CommonTree)adaptor.create(PATTERNNAME1);
            adaptor.addChild(root_0, PATTERNNAME1_tree);

            string_literal2=(Token)input.LT(1);
            match(input,15,FOLLOW_15_in_specification90); 
            pushFollow(FOLLOW_formula_in_specification93);
            formula3=formula();
            _fsp--;

            adaptor.addChild(root_0, formula3.getTree());

            }

            retval.stop = input.LT(-1);

                retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end specification

    public static class formula_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start formula
    // BPSL.g:55:1: formula : '\\\\exist' vardef predicateSection ;
    public final formula_return formula() throws RecognitionException {
        formula_return retval = new formula_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        Token string_literal4=null;
        vardef_return vardef5 = null;

        predicateSection_return predicateSection6 = null;


        CommonTree string_literal4_tree=null;

        try {
            // BPSL.g:55:10: ( '\\\\exist' vardef predicateSection )
            // BPSL.g:55:17: '\\\\exist' vardef predicateSection
            {
            root_0 = (CommonTree)adaptor.nil();

            string_literal4=(Token)input.LT(1);
            match(input,16,FOLLOW_16_in_formula108); 
            pushFollow(FOLLOW_vardef_in_formula111);
            vardef5=vardef();
            _fsp--;

            adaptor.addChild(root_0, vardef5.getTree());
            pushFollow(FOLLOW_predicateSection_in_formula113);
            predicateSection6=predicateSection();
            _fsp--;

            adaptor.addChild(root_0, predicateSection6.getTree());

            }

            retval.stop = input.LT(-1);

                retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end formula

    public static class vardef_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start vardef
    // BPSL.g:59:1: vardef : ( ID ( ',' ID )* '\\\\element' type ';' -> ^( type ( ID )+ ) | ID ( ',' ID )* '\\\\element' type ';' vardef -> ^( type ( ID )+ ) vardef );
    public final vardef_return vardef() throws RecognitionException {
        vardef_return retval = new vardef_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        Token ID7=null;
        Token char_literal8=null;
        Token ID9=null;
        Token string_literal10=null;
        Token char_literal12=null;
        Token ID13=null;
        Token char_literal14=null;
        Token ID15=null;
        Token string_literal16=null;
        Token char_literal18=null;
        type_return type11 = null;

        type_return type17 = null;

        vardef_return vardef19 = null;


        CommonTree ID7_tree=null;
        CommonTree char_literal8_tree=null;
        CommonTree ID9_tree=null;
        CommonTree string_literal10_tree=null;
        CommonTree char_literal12_tree=null;
        CommonTree ID13_tree=null;
        CommonTree char_literal14_tree=null;
        CommonTree ID15_tree=null;
        CommonTree string_literal16_tree=null;
        CommonTree char_literal18_tree=null;
        RewriteRuleTokenStream stream_19=new RewriteRuleTokenStream(adaptor,"token 19");
        RewriteRuleTokenStream stream_17=new RewriteRuleTokenStream(adaptor,"token 17");
        RewriteRuleTokenStream stream_ID=new RewriteRuleTokenStream(adaptor,"token ID");
        RewriteRuleTokenStream stream_18=new RewriteRuleTokenStream(adaptor,"token 18");
        RewriteRuleSubtreeStream stream_vardef=new RewriteRuleSubtreeStream(adaptor,"rule vardef");
        RewriteRuleSubtreeStream stream_type=new RewriteRuleSubtreeStream(adaptor,"rule type");
        try {
            // BPSL.g:59:8: ( ID ( ',' ID )* '\\\\element' type ';' -> ^( type ( ID )+ ) | ID ( ',' ID )* '\\\\element' type ';' vardef -> ^( type ( ID )+ ) vardef )
            int alt3=2;
            alt3 = dfa3.predict(input);
            switch (alt3) {
                case 1 :
                    // BPSL.g:59:10: ID ( ',' ID )* '\\\\element' type ';'
                    {
                    ID7=(Token)input.LT(1);
                    match(input,ID,FOLLOW_ID_in_vardef127); 
                    stream_ID.add(ID7);

                    // BPSL.g:59:13: ( ',' ID )*
                    loop1:
                    do {
                        int alt1=2;
                        int LA1_0 = input.LA(1);

                        if ( (LA1_0==17) ) {
                            alt1=1;
                        }


                        switch (alt1) {
                    	case 1 :
                    	    // BPSL.g:59:14: ',' ID
                    	    {
                    	    char_literal8=(Token)input.LT(1);
                    	    match(input,17,FOLLOW_17_in_vardef130); 
                    	    stream_17.add(char_literal8);

                    	    ID9=(Token)input.LT(1);
                    	    match(input,ID,FOLLOW_ID_in_vardef132); 
                    	    stream_ID.add(ID9);


                    	    }
                    	    break;

                    	default :
                    	    break loop1;
                        }
                    } while (true);

                    string_literal10=(Token)input.LT(1);
                    match(input,18,FOLLOW_18_in_vardef137); 
                    stream_18.add(string_literal10);

                    pushFollow(FOLLOW_type_in_vardef139);
                    type11=type();
                    _fsp--;

                    stream_type.add(type11.getTree());
                    char_literal12=(Token)input.LT(1);
                    match(input,19,FOLLOW_19_in_vardef141); 
                    stream_19.add(char_literal12);


                    // AST REWRITE
                    // elements: type, ID
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"token retval",retval!=null?retval.tree:null);

                    root_0 = (CommonTree)adaptor.nil();
                    // 59:45: -> ^( type ( ID )+ )
                    {
                        // BPSL.g:59:48: ^( type ( ID )+ )
                        {
                        CommonTree root_1 = (CommonTree)adaptor.nil();
                        root_1 = (CommonTree)adaptor.becomeRoot(stream_type.nextNode(), root_1);

                        if ( !(stream_ID.hasNext()) ) {
                            throw new RewriteEarlyExitException();
                        }
                        while ( stream_ID.hasNext() ) {
                            adaptor.addChild(root_1, stream_ID.next());

                        }
                        stream_ID.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }



                    }
                    break;
                case 2 :
                    // BPSL.g:60:5: ID ( ',' ID )* '\\\\element' type ';' vardef
                    {
                    ID13=(Token)input.LT(1);
                    match(input,ID,FOLLOW_ID_in_vardef156); 
                    stream_ID.add(ID13);

                    // BPSL.g:60:8: ( ',' ID )*
                    loop2:
                    do {
                        int alt2=2;
                        int LA2_0 = input.LA(1);

                        if ( (LA2_0==17) ) {
                            alt2=1;
                        }


                        switch (alt2) {
                    	case 1 :
                    	    // BPSL.g:60:9: ',' ID
                    	    {
                    	    char_literal14=(Token)input.LT(1);
                    	    match(input,17,FOLLOW_17_in_vardef159); 
                    	    stream_17.add(char_literal14);

                    	    ID15=(Token)input.LT(1);
                    	    match(input,ID,FOLLOW_ID_in_vardef161); 
                    	    stream_ID.add(ID15);


                    	    }
                    	    break;

                    	default :
                    	    break loop2;
                        }
                    } while (true);

                    string_literal16=(Token)input.LT(1);
                    match(input,18,FOLLOW_18_in_vardef166); 
                    stream_18.add(string_literal16);

                    pushFollow(FOLLOW_type_in_vardef168);
                    type17=type();
                    _fsp--;

                    stream_type.add(type17.getTree());
                    char_literal18=(Token)input.LT(1);
                    match(input,19,FOLLOW_19_in_vardef170); 
                    stream_19.add(char_literal18);

                    pushFollow(FOLLOW_vardef_in_vardef172);
                    vardef19=vardef();
                    _fsp--;

                    stream_vardef.add(vardef19.getTree());

                    // AST REWRITE
                    // elements: type, ID, vardef
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"token retval",retval!=null?retval.tree:null);

                    root_0 = (CommonTree)adaptor.nil();
                    // 60:47: -> ^( type ( ID )+ ) vardef
                    {
                        // BPSL.g:60:50: ^( type ( ID )+ )
                        {
                        CommonTree root_1 = (CommonTree)adaptor.nil();
                        root_1 = (CommonTree)adaptor.becomeRoot(stream_type.nextNode(), root_1);

                        if ( !(stream_ID.hasNext()) ) {
                            throw new RewriteEarlyExitException();
                        }
                        while ( stream_ID.hasNext() ) {
                            adaptor.addChild(root_1, stream_ID.next());

                        }
                        stream_ID.reset();

                        adaptor.addChild(root_0, root_1);
                        }
                        adaptor.addChild(root_0, stream_vardef.next());

                    }



                    }
                    break;

            }
            retval.stop = input.LT(-1);

                retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end vardef

    public static class type_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start type
    // BPSL.g:65:1: type : ( '\\\\C' -> CLASSDEF | '\\\\V' -> TYPEDVARDEF | '\\\\M' -> METHODDEF );
    public final type_return type() throws RecognitionException {
        type_return retval = new type_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        Token string_literal20=null;
        Token string_literal21=null;
        Token string_literal22=null;

        CommonTree string_literal20_tree=null;
        CommonTree string_literal21_tree=null;
        CommonTree string_literal22_tree=null;
        RewriteRuleTokenStream stream_21=new RewriteRuleTokenStream(adaptor,"token 21");
        RewriteRuleTokenStream stream_20=new RewriteRuleTokenStream(adaptor,"token 20");
        RewriteRuleTokenStream stream_22=new RewriteRuleTokenStream(adaptor,"token 22");

        try {
            // BPSL.g:65:7: ( '\\\\C' -> CLASSDEF | '\\\\V' -> TYPEDVARDEF | '\\\\M' -> METHODDEF )
            int alt4=3;
            switch ( input.LA(1) ) {
            case 20:
                {
                alt4=1;
                }
                break;
            case 21:
                {
                alt4=2;
                }
                break;
            case 22:
                {
                alt4=3;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("65:1: type : ( '\\\\C' -> CLASSDEF | '\\\\V' -> TYPEDVARDEF | '\\\\M' -> METHODDEF );", 4, 0, input);

                throw nvae;
            }

            switch (alt4) {
                case 1 :
                    // BPSL.g:65:9: '\\\\C'
                    {
                    string_literal20=(Token)input.LT(1);
                    match(input,20,FOLLOW_20_in_type197); 
                    stream_20.add(string_literal20);


                    // AST REWRITE
                    // elements: 
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"token retval",retval!=null?retval.tree:null);

                    root_0 = (CommonTree)adaptor.nil();
                    // 66:4: -> CLASSDEF
                    {
                        adaptor.addChild(root_0, adaptor.create(CLASSDEF, "CLASSDEF"));

                    }



                    }
                    break;
                case 2 :
                    // BPSL.g:67:5: '\\\\V'
                    {
                    string_literal21=(Token)input.LT(1);
                    match(input,21,FOLLOW_21_in_type210); 
                    stream_21.add(string_literal21);


                    // AST REWRITE
                    // elements: 
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"token retval",retval!=null?retval.tree:null);

                    root_0 = (CommonTree)adaptor.nil();
                    // 68:4: -> TYPEDVARDEF
                    {
                        adaptor.addChild(root_0, adaptor.create(TYPEDVARDEF, "TYPEDVARDEF"));

                    }



                    }
                    break;
                case 3 :
                    // BPSL.g:69:5: '\\\\M'
                    {
                    string_literal22=(Token)input.LT(1);
                    match(input,22,FOLLOW_22_in_type223); 
                    stream_22.add(string_literal22);


                    // AST REWRITE
                    // elements: 
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"token retval",retval!=null?retval.tree:null);

                    root_0 = (CommonTree)adaptor.nil();
                    // 70:4: -> METHODDEF
                    {
                        adaptor.addChild(root_0, adaptor.create(METHODDEF, "METHODDEF"));

                    }



                    }
                    break;

            }
            retval.stop = input.LT(-1);

                retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end type

    public static class predicateSection_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start predicateSection
    // BPSL.g:73:1: predicateSection : ( atom | atom DISJUNCTION predicateSection );
    public final predicateSection_return predicateSection() throws RecognitionException {
        predicateSection_return retval = new predicateSection_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        Token DISJUNCTION25=null;
        atom_return atom23 = null;

        atom_return atom24 = null;

        predicateSection_return predicateSection26 = null;


        CommonTree DISJUNCTION25_tree=null;

        try {
            // BPSL.g:73:18: ( atom | atom DISJUNCTION predicateSection )
            int alt5=2;
            int LA5_0 = input.LA(1);

            if ( (LA5_0==PREDICATE) ) {
                int LA5_1 = input.LA(2);

                if ( (LA5_1==23) ) {
                    int LA5_2 = input.LA(3);

                    if ( (LA5_2==ID) ) {
                        int LA5_3 = input.LA(4);

                        if ( (LA5_3==17) ) {
                            int LA5_4 = input.LA(5);

                            if ( (LA5_4==ID) ) {
                                int LA5_5 = input.LA(6);

                                if ( (LA5_5==24) ) {
                                    int LA5_6 = input.LA(7);

                                    if ( (LA5_6==DISJUNCTION) ) {
                                        alt5=2;
                                    }
                                    else if ( (LA5_6==EOF) ) {
                                        alt5=1;
                                    }
                                    else {
                                        NoViableAltException nvae =
                                            new NoViableAltException("73:1: predicateSection : ( atom | atom DISJUNCTION predicateSection );", 5, 6, input);

                                        throw nvae;
                                    }
                                }
                                else {
                                    NoViableAltException nvae =
                                        new NoViableAltException("73:1: predicateSection : ( atom | atom DISJUNCTION predicateSection );", 5, 5, input);

                                    throw nvae;
                                }
                            }
                            else {
                                NoViableAltException nvae =
                                    new NoViableAltException("73:1: predicateSection : ( atom | atom DISJUNCTION predicateSection );", 5, 4, input);

                                throw nvae;
                            }
                        }
                        else {
                            NoViableAltException nvae =
                                new NoViableAltException("73:1: predicateSection : ( atom | atom DISJUNCTION predicateSection );", 5, 3, input);

                            throw nvae;
                        }
                    }
                    else {
                        NoViableAltException nvae =
                            new NoViableAltException("73:1: predicateSection : ( atom | atom DISJUNCTION predicateSection );", 5, 2, input);

                        throw nvae;
                    }
                }
                else {
                    NoViableAltException nvae =
                        new NoViableAltException("73:1: predicateSection : ( atom | atom DISJUNCTION predicateSection );", 5, 1, input);

                    throw nvae;
                }
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("73:1: predicateSection : ( atom | atom DISJUNCTION predicateSection );", 5, 0, input);

                throw nvae;
            }
            switch (alt5) {
                case 1 :
                    // BPSL.g:73:20: atom
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    pushFollow(FOLLOW_atom_in_predicateSection241);
                    atom23=atom();
                    _fsp--;

                    adaptor.addChild(root_0, atom23.getTree());

                    }
                    break;
                case 2 :
                    // BPSL.g:73:27: atom DISJUNCTION predicateSection
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    pushFollow(FOLLOW_atom_in_predicateSection245);
                    atom24=atom();
                    _fsp--;

                    adaptor.addChild(root_0, atom24.getTree());
                    DISJUNCTION25=(Token)input.LT(1);
                    match(input,DISJUNCTION,FOLLOW_DISJUNCTION_in_predicateSection247); 
                    pushFollow(FOLLOW_predicateSection_in_predicateSection250);
                    predicateSection26=predicateSection();
                    _fsp--;

                    adaptor.addChild(root_0, predicateSection26.getTree());

                    }
                    break;

            }
            retval.stop = input.LT(-1);

                retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end predicateSection

    public static class atom_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start atom
    // BPSL.g:76:1: atom : PREDICATE '(' term ',' term ')' -> ^( PREDICATE term term ) ;
    public final atom_return atom() throws RecognitionException {
        atom_return retval = new atom_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        Token PREDICATE27=null;
        Token char_literal28=null;
        Token char_literal30=null;
        Token char_literal32=null;
        term_return term29 = null;

        term_return term31 = null;


        CommonTree PREDICATE27_tree=null;
        CommonTree char_literal28_tree=null;
        CommonTree char_literal30_tree=null;
        CommonTree char_literal32_tree=null;
        RewriteRuleTokenStream stream_17=new RewriteRuleTokenStream(adaptor,"token 17");
        RewriteRuleTokenStream stream_23=new RewriteRuleTokenStream(adaptor,"token 23");
        RewriteRuleTokenStream stream_24=new RewriteRuleTokenStream(adaptor,"token 24");
        RewriteRuleTokenStream stream_PREDICATE=new RewriteRuleTokenStream(adaptor,"token PREDICATE");
        RewriteRuleSubtreeStream stream_term=new RewriteRuleSubtreeStream(adaptor,"rule term");
        try {
            // BPSL.g:76:7: ( PREDICATE '(' term ',' term ')' -> ^( PREDICATE term term ) )
            // BPSL.g:76:9: PREDICATE '(' term ',' term ')'
            {
            PREDICATE27=(Token)input.LT(1);
            match(input,PREDICATE,FOLLOW_PREDICATE_in_atom264); 
            stream_PREDICATE.add(PREDICATE27);

            char_literal28=(Token)input.LT(1);
            match(input,23,FOLLOW_23_in_atom266); 
            stream_23.add(char_literal28);

            pushFollow(FOLLOW_term_in_atom268);
            term29=term();
            _fsp--;

            stream_term.add(term29.getTree());
            char_literal30=(Token)input.LT(1);
            match(input,17,FOLLOW_17_in_atom270); 
            stream_17.add(char_literal30);

            pushFollow(FOLLOW_term_in_atom272);
            term31=term();
            _fsp--;

            stream_term.add(term31.getTree());
            char_literal32=(Token)input.LT(1);
            match(input,24,FOLLOW_24_in_atom274); 
            stream_24.add(char_literal32);


            // AST REWRITE
            // elements: PREDICATE, term, term
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"token retval",retval!=null?retval.tree:null);

            root_0 = (CommonTree)adaptor.nil();
            // 77:4: -> ^( PREDICATE term term )
            {
                // BPSL.g:77:7: ^( PREDICATE term term )
                {
                CommonTree root_1 = (CommonTree)adaptor.nil();
                root_1 = (CommonTree)adaptor.becomeRoot(stream_PREDICATE.next(), root_1);

                adaptor.addChild(root_1, stream_term.next());
                adaptor.addChild(root_1, stream_term.next());

                adaptor.addChild(root_0, root_1);
                }

            }



            }

            retval.stop = input.LT(-1);

                retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end atom

    public static class term_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start term
    // BPSL.g:82:1: term : ID ;
    public final term_return term() throws RecognitionException {
        term_return retval = new term_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        Token ID33=null;

        CommonTree ID33_tree=null;

        try {
            // BPSL.g:82:7: ( ID )
            // BPSL.g:82:9: ID
            {
            root_0 = (CommonTree)adaptor.nil();

            ID33=(Token)input.LT(1);
            match(input,ID,FOLLOW_ID_in_term301); 
            ID33_tree = (CommonTree)adaptor.create(ID33);
            adaptor.addChild(root_0, ID33_tree);


            }

            retval.stop = input.LT(-1);

                retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end term


    protected DFA3 dfa3 = new DFA3(this);
    static final String DFA3_eotS =
        "\13\uffff";
    static final String DFA3_eofS =
        "\13\uffff";
    static final String DFA3_minS =
        "\1\14\1\21\1\14\1\24\1\21\3\23\1\14\2\uffff";
    static final String DFA3_maxS =
        "\1\14\1\22\1\14\1\26\1\22\3\23\1\15\2\uffff";
    static final String DFA3_acceptS =
        "\11\uffff\1\2\1\1";
    static final String DFA3_specialS =
        "\13\uffff}>";
    static final String[] DFA3_transitionS = {
            "\1\1",
            "\1\2\1\3",
            "\1\4",
            "\1\5\1\6\1\7",
            "\1\2\1\3",
            "\1\10",
            "\1\10",
            "\1\10",
            "\1\11\1\12",
            "",
            ""
    };

    static final short[] DFA3_eot = DFA.unpackEncodedString(DFA3_eotS);
    static final short[] DFA3_eof = DFA.unpackEncodedString(DFA3_eofS);
    static final char[] DFA3_min = DFA.unpackEncodedStringToUnsignedChars(DFA3_minS);
    static final char[] DFA3_max = DFA.unpackEncodedStringToUnsignedChars(DFA3_maxS);
    static final short[] DFA3_accept = DFA.unpackEncodedString(DFA3_acceptS);
    static final short[] DFA3_special = DFA.unpackEncodedString(DFA3_specialS);
    static final short[][] DFA3_transition;

    static {
        int numStates = DFA3_transitionS.length;
        DFA3_transition = new short[numStates][];
        for (int i=0; i<numStates; i++) {
            DFA3_transition[i] = DFA.unpackEncodedString(DFA3_transitionS[i]);
        }
    }

    class DFA3 extends DFA {

        public DFA3(BaseRecognizer recognizer) {
            this.recognizer = recognizer;
            this.decisionNumber = 3;
            this.eot = DFA3_eot;
            this.eof = DFA3_eof;
            this.min = DFA3_min;
            this.max = DFA3_max;
            this.accept = DFA3_accept;
            this.special = DFA3_special;
            this.transition = DFA3_transition;
        }
        public String getDescription() {
            return "59:1: vardef : ( ID ( ',' ID )* '\\\\element' type ';' -> ^( type ( ID )+ ) | ID ( ',' ID )* '\\\\element' type ';' vardef -> ^( type ( ID )+ ) vardef );";
        }
    }
 

    public static final BitSet FOLLOW_PATTERNNAME_in_specification88 = new BitSet(new long[]{0x0000000000008000L});
    public static final BitSet FOLLOW_15_in_specification90 = new BitSet(new long[]{0x0000000000010000L});
    public static final BitSet FOLLOW_formula_in_specification93 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_16_in_formula108 = new BitSet(new long[]{0x0000000000001000L});
    public static final BitSet FOLLOW_vardef_in_formula111 = new BitSet(new long[]{0x0000000000002000L});
    public static final BitSet FOLLOW_predicateSection_in_formula113 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_vardef127 = new BitSet(new long[]{0x0000000000060000L});
    public static final BitSet FOLLOW_17_in_vardef130 = new BitSet(new long[]{0x0000000000001000L});
    public static final BitSet FOLLOW_ID_in_vardef132 = new BitSet(new long[]{0x0000000000060000L});
    public static final BitSet FOLLOW_18_in_vardef137 = new BitSet(new long[]{0x0000000000700000L});
    public static final BitSet FOLLOW_type_in_vardef139 = new BitSet(new long[]{0x0000000000080000L});
    public static final BitSet FOLLOW_19_in_vardef141 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_vardef156 = new BitSet(new long[]{0x0000000000060000L});
    public static final BitSet FOLLOW_17_in_vardef159 = new BitSet(new long[]{0x0000000000001000L});
    public static final BitSet FOLLOW_ID_in_vardef161 = new BitSet(new long[]{0x0000000000060000L});
    public static final BitSet FOLLOW_18_in_vardef166 = new BitSet(new long[]{0x0000000000700000L});
    public static final BitSet FOLLOW_type_in_vardef168 = new BitSet(new long[]{0x0000000000080000L});
    public static final BitSet FOLLOW_19_in_vardef170 = new BitSet(new long[]{0x0000000000001000L});
    public static final BitSet FOLLOW_vardef_in_vardef172 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_20_in_type197 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_21_in_type210 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_22_in_type223 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_atom_in_predicateSection241 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_atom_in_predicateSection245 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_DISJUNCTION_in_predicateSection247 = new BitSet(new long[]{0x0000000000002000L});
    public static final BitSet FOLLOW_predicateSection_in_predicateSection250 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_PREDICATE_in_atom264 = new BitSet(new long[]{0x0000000000800000L});
    public static final BitSet FOLLOW_23_in_atom266 = new BitSet(new long[]{0x0000000000001000L});
    public static final BitSet FOLLOW_term_in_atom268 = new BitSet(new long[]{0x0000000000020000L});
    public static final BitSet FOLLOW_17_in_atom270 = new BitSet(new long[]{0x0000000000001000L});
    public static final BitSet FOLLOW_term_in_atom272 = new BitSet(new long[]{0x0000000001000000L});
    public static final BitSet FOLLOW_24_in_atom274 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_term301 = new BitSet(new long[]{0x0000000000000002L});

}